package com.lwb.ztx.lives.widget;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lwb.ztx.R;
import com.lwb.ztx.bean.LiveBean;
import com.lwb.ztx.utils.ListUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/6/16.
 */
public class LiveLandChannelAdapter extends RecyclerView.Adapter {
    private List<LiveBean> beanList;
    private OnChannelItemClickListener listener;
    private int currentIndex;
    public LiveLandChannelAdapter(List<LiveBean> beanList,OnChannelItemClickListener listener) {
        this.beanList = beanList;
        this.listener = listener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.live_land_channel_item, parent, false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        itemViewHolder.channel.setText(beanList.get(position).getTitle());
        itemViewHolder.index = position;
        if (position == currentIndex) {
            itemViewHolder.channel.setTextColor(0xFFEB413D);
        } else {
            itemViewHolder.channel.setTextColor(0xFFFFFFFF);
        }
    }

    @Override
    public int getItemCount() {
        return ListUtils.getSize(beanList);
    }

    class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        TextView channel;
        int index;
        public ItemViewHolder(View itemView) {
            super(itemView);
            channel = (TextView) itemView.findViewById(R.id.land_channel_view);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.onChannelItemClick(index);
            }
        }
    }

    public void setCurrentIndex(int currentIndex) {
        this.currentIndex = currentIndex;
    }

    public interface OnChannelItemClickListener {
        void onChannelItemClick(int index);
    }

}
